<!--
  @author:  long
  @date:    2023/3/7
  @file:    资料详情
  @require:
-->
<template>
  <div>
    <div v-for="(item, index) in overviewData" class="mb-5" :key="index">
      <el-descriptions :column="column" border>
        <template #title>
          <el-row>
            <el-col :span="12">
              <!--          <div class="text-gray-600 text-sm">-->
              <!--            <i class="i-bi-bookmarks-fill"></i>-->
              <!--            {{ item.title }}-->
              <!--          </div>-->
              <TitleName
                :title="item.title"
                icon="i-carbon-bookmark-filled"
              ></TitleName>
            </el-col>
            <el-col :span="12" class="text-right">
              <el-button link size="small">
                <div v-if="item.handleTitle == 'handle'">
                  <el-button type="primary" icon="Edit" @click="toUpdate"
                    >编辑
                  </el-button>
                  <el-button type="primary" icon="UploadFilled" plain
                    >导出
                  </el-button>
                </div>
                <div v-else>
                  {{ item.handleTitle }}
                </div>
              </el-button>
            </el-col>
          </el-row>
        </template>
        <el-descriptions-item
          v-for="(t, i) in item.list"
          :key="i"
          :label="t.label"
          label-align="right"
          label-class-name="w-6/24"
          class-name="w-6/24"
        >
          <!--      客户类型        -->
          <template v-if="t.prop === 'type'">企业</template>
          <!--      所属行业        -->
          <template v-else-if="t.prop === 'industryTypeCode'">
            <dict-tag
              :options="industry_category"
              :value="overviewInfo[t.prop]"
            />
          </template>
          <!--      客户类别        -->
          <template v-else-if="t.prop === 'customerType'">
            <dict-tag :options="customer_class" :value="overviewInfo[t.prop]" />
          </template>
          <!--      客户星级        -->
          <template v-else-if="t.prop === 'starRating'">
            <el-rate v-model="overviewInfo[t.prop]" />
          </template>
          <!--      客户来源        -->
          <template v-else-if="t.prop === 'origin'">
            <dict-tag
              :options="customer_source"
              :value="overviewInfo[t.prop]"
            />
          </template>
          <!--      客户状态        -->
          <template v-else-if="t.prop === 'status'">
            <dict-tag
              :options="customer_status"
              :value="overviewInfo[t.prop]"
            />
          </template>
          <!--      纳税人性质        -->
          <template v-else-if="t.prop === 'taxNature'">
            <dict-tag :options="tax_grade" :value="overviewInfo[t.prop]" />
          </template>
          <!--      客户等级        -->
          <template v-else-if="t.prop === 'customerLevel'">
            <dict-tag :options="customer_level" :value="overviewInfo[t.prop]" />
          </template>
          <!--       是否开票 /是否诺诺开票 /是否51开票       -->
          <template
            v-else-if="
              t.prop === 'isIssueInvNuonuo' ||
              t.prop === 'isIssueInv' ||
              t.prop === 'isIssueInv51'
            "
          >
            <dict-tag :options="sys_yes_no" :value="overviewInfo[t.prop]" />
          </template>
          <!--     数电配置       -->
          <template v-else-if="t.prop === 'isDigital'">
            {{
              (overviewInfo[t.prop] == '1'
                ? '是'
                : overviewInfo[t.prop] == '0'
                ? '否'
                : '') + `(${overviewInfo.digitalInfo})`
            }}
          </template>
          <!--      信用等级        -->
          <template v-else-if="t.prop === 'creditListId'">
            <dict-tag :options="credit_rating" :value="overviewInfo[t.prop]" />
          </template>
          <!--      职务        -->
          <template v-else-if="t.prop === 'dutyCode'">
            <dict-tag :options="duties_dict" :value="overviewInfo[t.prop]" />
          </template>
          <!--      岗位        -->
          <template v-else-if="t.prop === 'postCode'">
            <dict-tag :options="post_dict" :value="overviewInfo[t.prop]" />
          </template>
          <!--      非居民企业标志       -->
          <template v-else-if="t.prop === 'fjmqybz'">
            {{ overviewInfo[t.prop] == 'Y' ? '是' : '否' }}
          </template>
          <!--      文化事业建设费缴费信息登记标志       -->
          <template v-else-if="t.prop === 'whsyjsfjfxxdjbz'">
            {{ overviewInfo[t.prop] == 'Y' ? '是' : '否' }}
          </template>
          <!--      国有控股类型代码       -->
          <template v-else-if="t.prop === 'gykglxDm'">
            <dict-tag :options="gykglx_type" :value="overviewInfo[t.prop]" />
          </template>
          <!--      会计制度(准则)代码       -->
          <template v-else-if="t.prop === 'kjzdzzDm'">
            <dict-tag :options="kjzdzz_code" :value="overviewInfo[t.prop]" />
          </template>
          <!--      增值税企业类型代码       -->
          <template v-else-if="t.prop === 'zzsqylxDm'">
            <dict-tag :options="zzsqjlx_type" :value="overviewInfo[t.prop]" />
          </template>
          <!--      总分机构类型代码       -->
          <template v-else-if="t.prop === 'zfjglxDm'">
            <dict-tag :options="zfjglx_type" :value="overviewInfo[t.prop]" />
          </template>
          <template v-else>{{ overviewInfo[t.prop] }}</template>
        </el-descriptions-item>
      </el-descriptions>
    </div>
  </div>
</template>

<script setup name="DetailsInfo">
import { getCurrentInstance } from 'vue'
import { CodeToText } from 'element-china-area-data'
import { getDept } from '@/api/system/dept'
import { useRouter } from 'vue-router'
import useCommonStore from '@/store/modules/common'
import { getTreeNodeByParam } from '@/utils/commo'

const router = useRouter()
const commonStore = useCommonStore()

const { proxy } = getCurrentInstance()
const props = defineProps({
  details: {
    type: Object,
    default: () => {
      return {}
    }
  }
})
// 字典 具体查看根目录DICT.md文件
const {
  industry_category,
  customer_class,
  post_dict,
  duties_dict,
  customer_status,
  customer_source,
  tax_grade,
  customer_level,
  sys_yes_no,
  credit_rating
} = proxy.useDict(
  'industry_category',
  'customer_class',
  'post_dict',
  'duties_dict',
  'customer_status',
  'customer_source',
  'tax_grade',
  'customer_level',
  'sys_yes_no',
  'credit_rating'
)
const data = reactive({
  overviewInfo: {},
  overviewData: [
    {
      title: '基本信息',
      handleTitle: 'handle',
      list: [
        { label: '客户名称', prop: 'customerName' },
        { label: '客户类别', prop: 'customerType' },
        { label: '客户类型', prop: 'type' },
        { label: '所属行业', prop: 'industryTypeCode' },
        { label: '客户星级', prop: 'starRating' },
        { label: '客户来源', prop: 'origin' },
        { label: '客户状态', prop: 'status' },
        { label: '客户归属', prop: 'userName' }
      ]
    },
    {
      title: '附加信息',
      handleTitle: '',
      list: [
        { label: '纳税人性质', prop: 'taxNature' },
        { label: '客户等级', prop: 'customerLevel' },
        { label: '所属企业', prop: 'parentName' },
        { label: '归属公司', prop: 'orgName' },
        { label: '数电配置', prop: 'isDigital' },
        { label: '信用等级', prop: 'creditListId' },
        { label: '征信积分', prop: 'creditScore' },
        { label: '所在地区', prop: 'cityName' },
        { label: '地址说明', prop: 'addressName' },
        { label: '详细地址', prop: 'address' },
        { label: '企业规模', prop: 'scale' },
        { label: '上级客户', prop: 'parentName' },
        { label: '备注信息', prop: 'remark' }
      ]
    },
    {
      title: '财务信息',
      handleTitle: '',
      list: [
        { label: '财务软件品牌', prop: 'fdinfoSoftwareBrand' },
        { label: '财务软件版本号', prop: 'fdinfoSoftwareVersion' },
        { label: '开票额（元）', prop: 'fdinfoIssueAmount' },
        { label: '开票量', prop: 'fdinfoIssueCount' },
        { label: '财务人员', prop: 'fdinfoPersonCount' },
        { label: '已成交金额', prop: '' },
        { label: '已回款金额', prop: '' },
        { label: '已开票金额', prop: '' },
        { label: '未开票金额', prop: '' },
        { label: '潜在交易金额', prop: '' },
        { label: '费用总金额', prop: '' }
      ]
    },
    {
      title: '开票信息',
      handleTitle: '',
      list: [
        { label: '是否开票', prop: 'isIssueInv' },
        { label: '是否诺诺开票', prop: 'isIssueInvNuonuo' },
        { label: '是否51开票', prop: 'isIssueInv51' }
      ]
    },
    {
      title: '系统信息',
      handleTitle: '',
      list: [
        { label: '系统编号', prop: 'systemNumber' },
        { label: '协作人员', prop: '' },
        { label: '所属部门', prop: 'deptName' },
        { label: '创建人员', prop: 'createBy' },
        { label: '创建时间', prop: 'createTime' },
        { label: '更新时间', prop: 'updateTime' },
        { label: '最后跟进', prop: 'statusUpdateTime' },
        { label: '下次跟进', prop: 'statusUpdateTime' }
      ]
    },
    {
      title: '校验信息',
      handleTitle: '',
      list: [
        { label: '企业注册时间', prop: 'djrq' },
        { label: '行业类型', prop: 'hydm' },
        { label: '从业人数', prop: 'cyrs' },
        { label: '主管税务所(科、分局)名称', prop: 'zgswskfjMc' },
        { label: '非居民企业标志', prop: 'fjmqybz' },
        { label: '文化事业建设费缴费信息登记标志', prop: 'whsyjsfjfxxdjbz' },
        { label: '国有控股类型代码', prop: 'gykglxDm' },
        { label: '会计制度(准则)代码', prop: 'kjzdzzDm' },
        { label: '增值税企业类型代码', prop: 'zzsqylxDm' },
        { label: '经营范围', prop: 'jyfw' },
        { label: '总分机构类型代码', prop: 'zfjglxDm' },
        { label: '税务代理人名称', prop: 'swdlrmc' }
      ]
    }
  ]
})
const { overviewData, overviewInfo } = toRefs(data)

const column = ref(2)

watchEffect(() => {
  setInfo(props.details)
})

// 字典 具体查看根目录DICT.md文件
const { gykglx_type, zfjglx_type, zzsqjlx_type, kjzdzz_code } = proxy.useDict(
  'gykglx_type',
  'zfjglx_type',
  'zzsqjlx_type',
  'kjzdzz_code'
)

// 初始化数据处理
async function setInfo(details) {
  console.info('details', details)
  if (details.cityCode != null) {
    let arr = details.cityCode.split(',')
    details.cityName =
      CodeToText[arr[0]] + '-' + CodeToText[arr[1]] + '-' + CodeToText[arr[2]]
  }
  if (details.deptId != null) {
    let deptRes = await getDept(details.deptId)
    details.deptName = deptRes.data.deptName
  }
  // 获取归属公司名称
  commonStore.getCompanyData().then(data => {
    let o = getTreeNodeByParam(data, details.orgId, 'id', [])
    details.orgName = o[0].label
  })

  overviewInfo.value = details
}

function toUpdate() {
  router.push({
    path: '/customerManage/customerModules/customerEdit',
    query: {
      flag: 'update',
      customerId: router.currentRoute.value.query.customerId
    }
  })
}
</script>

<style scoped lang="scss">
::v-deep .el-descriptions__title {
  width: 100% !important;
}
</style>
